package mh.entity.object.attributes;

import mh.entity.Entity;
import mh.entity.object.EntityObject;

public class ObjectAttributeWalkable extends ObjectAttribute {
	/**
	 * Array of valid access directions
	 */
	boolean[]			validDirections	= { true, true, true, true };

	/**
	 * Position of the top access bit
	 */
	private static int	top_pos			= 0;

	/**
	 * Position of the top access bit
	 */
	private static int	right_pos		= 1;

	/**
	 * Position of the top access bit
	 */
	private static int	bottom_pos		= 2;

	/**
	 * Position of the top access bit
	 */
	private static int	left_pos		= 3;

	/**
	 * Constructor
	 */
	public ObjectAttributeWalkable(EntityObject o) {
		super(o);
	}

	public ObjectAttributeWalkable(EntityObject o, boolean top, boolean right, boolean bottom, boolean left) {
		super(o);
		this.setTopAccessible(top);
		this.setRightAccessible(right);
		this.setBottomAccessible(bottom);
		this.setLeftAccessible(left);
	}

	/**
	 * Sets the right position accessible
	 * 
	 * @param value
	 */
	public ObjectAttributeWalkable setRightAccessible(boolean value) {
		this.validDirections[right_pos] = value;
		return this;
	}

	/**
	 * Sets the top position accessible
	 * 
	 * @param value
	 */
	public ObjectAttributeWalkable setTopAccessible(boolean value) {
		this.validDirections[top_pos] = value;
		return this;
	}

	/**
	 * Sets the top position accessible
	 * 
	 * @param value
	 */
	public ObjectAttributeWalkable setBottomAccessible(boolean value) {
		this.validDirections[bottom_pos] = value;
		return this;
	}

	/**
	 * Sets the top position accessible
	 * 
	 * @param value
	 */
	public ObjectAttributeWalkable setLeftAccessible(boolean value) {
		this.validDirections[left_pos] = value;
		return this;
	}

	/**
	 * Returns if the action of walking over the object is valid or not
	 * 
	 * @return boolean
	 */
	@Override
	public boolean isValid(Entity interact) {//Can only be accessed from the top/right/bottom/left nearest cell
		int objX = (int) this.obj.getX();
		int objY = (int) this.obj.getY();
		int interactX = (int) interact.getX();
		int interactY = (int) interact.getY();

		return this.validDirections[ObjectAttribute.getInteractionDirection(objX, objY, interactX, interactY) / 2]; // divided by 2 because will return 1 OR 3 OR 5 Or 7
	}

	/**
	 * True if the Object is the same type of this object
	 * 
	 * @return boolean
	 */
	@Override
	public boolean equals(Object o) {
		return o instanceof ObjectAttributeWalkable;
	}
}
